package com.wyvoid.forum.web.action.admin.usergroup;

import com.wyvoid.forum.web.action.admin.BaseAdminAction;
import com.wyvoid.forum.service.IAdminGroupService;
import com.wyvoid.forum.domain.AdminGroup;
import com.wyvoid.forum.domain.UserGroup;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.integration.spring.SpringBean;

/**
 * Created by IntelliJ IDEA.
 * User: qijing
 * Date: 2007-7-10
 * Time: 9:46:59
 * To change this template use File | Settings | File Templates.
 */
@UrlBinding(value = "/admin/adminGroupDroit.do")
public class AdminGroupDroitAction extends BaseAdminAction {

    String[] permissionsStr;
    private AdminGroup adminGroup;
    @SpringBean
    private IAdminGroupService adminGroupService;

    public IAdminGroupService getAdminGroupService() {
        return adminGroupService;
    }

    @SpringBean
    public void setAdminGroupService(IAdminGroupService adminGroupService) {
        this.adminGroupService = adminGroupService;
    }

    public AdminGroup getAdminGroup() {
        return adminGroup;
    }

    public void setAdminGroup(AdminGroup adminGroup) {
        this.adminGroup = adminGroup;
    }

    public String[] getPermissionsStr() {
        return permissionsStr;
    }

    public void setPermissionsStr(String[] permissionsStr) {
        this.permissionsStr = permissionsStr;
    }

    @DefaultHandler
    @DontValidate
    public Resolution viewAdminGroupDroit() {
//        SessionUser user = getContext().getUser();
//         if(user!=null){
        long longId = 0;
        longId = Long.parseLong(context.getRequest().getParameter("id"));
        if (longId == 0) {
            return null;
        } else {
            adminGroup = adminGroupService.getAdminGroup(longId);
            return getAdminResolution("usergroup/viewAdminGroupDroit");
        }

//        }else{
//                   return null;
//        }
    }
    
     @DontValidate
     public Resolution setDetaiPurview() {
        String permissions = "|";
        long longId = 0;
         String str=null;
        longId = Long.parseLong(context.getRequest().getParameter("id"));
        for (int i = 0; i < permissionsStr.length; i++) {
            str=context.getRequest().getParameter(permissionsStr[i]);
            System.out.println(str);
            if(!str.equals("0")){
            permissions+=str+"|";
            }
        }
        adminGroupService.updateAdminGroup(longId,permissions);
        return new RedirectResolution("/forum/admin/adminGroupDroit.do?id="+longId, false);
    }
}
